package com.leejw.tradeblogsystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leejw.tradeblogsystem.common.Result;
import com.leejw.tradeblogsystem.common.TradeUtil;
import com.leejw.tradeblogsystem.mapper.ArticleMapper;
import com.leejw.tradeblogsystem.model.Article;
import com.leejw.tradeblogsystem.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author: jwli3
 * @Desc:
 * @create: 2024-08-22
 **/
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Autowired
    ArticleMapper articleMapper;
    @Override
    public Result saveArticle(Article articleVO) {
        Article article = new Article();
        article.setViewStatus(articleVO.getViewStatus());
        article.setCommentStatus(articleVO.getCommentStatus());
        article.setRecommendStatus(articleVO.getRecommendStatus());
        article.setArticleTitle(articleVO.getArticleTitle());
        article.setArticleContent(articleVO.getArticleContent());
        article.setSortId(articleVO.getSortId());
        article.setLabelId(articleVO.getLabelId());
        article.setUserId(1);
        save(article);
        return Result.success(article);
    }

    @Override
    public Result deleteArticle(Integer id) {
        articleMapper.deleteById(id);
        return Result.success("");
    }

    @Override
    public Result updateArticle(Article articleVO) {
        int i = articleMapper.updateById(articleVO);
        return Result.success();
    }

    @Override
    public List<Article> findAllArticle() {
        List<Article> articles = articleMapper.queryAll();
        return articles;
    }

    @Override
    public List<Article> findArticle(String createTime) {
        List<Article> articles = articleMapper.findArticle(createTime);
        return articles;
    }

    @Override
    public List<Article> findRecommendArticle() {
        List<Article> articles = articleMapper.findRecommendArticle();
        return articles;
    }

    @Override
    public Article findArticleById(Integer id) {
        Article article = articleMapper.selectById(id);
        return article;
    }


}
